perm filename LSPLIB[P,JRA] blob sn#609408 filedate 1981-08-29 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00005 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	system extension for library functions.
C00005 00003
C00008 00004
C00010 00005	 behavior of loader:
C00012 ENDMK
C⊗;
system extension for library functions.

conditions:(may be relazed later)

1. only calls system or lib stuff --no exprs

2. non-local reference to vars not allowed

3. position independent z-80 code (?? can use iy?)

4. size restricted by size of system buffer (probably 1KB)



format

ATOM			FASL STRUCTURE
----------		----------
|	 |		| NAME	 | (TYPICALLY SAME AS ATOM, BUT NEED NOT BE)
----------		----------
| VALUE	-+-→------↓	|  R | O |
----------	  ↓	----------
|	 |	  +→---→| JMPADR |→→+ ←+   (OR NIL)
----------		----------  ↓  ↑
|	 |		| FILE	 |  |  |
----------		----------  |  |
          		| REC|POS|  ↓  |
           		----------  |  ↑
		+←---------←-------←+  |
		|		       |
SYSTEM BUFFER   ↓		       |
		|		       ↑
----------←---← | ←--+	----------     |
|	 |←---←-+    ↑	| NAME	 |→---→+ (RETRIEVE AS LOC-4) = VALUE
|        |	     |	----------
|	 |	     +←-| ORG	 | (NOTE: JMPADR IS OFFSET BY NO. EXT. + FASL NAME
----------		----------
|	 |		| SIZE	 |
|        |		----------
|	 |		   . . .  
----------		----------
|	 |		| NAME	 |
			----------
   . . . 	 	| ORG	 |
|	 |		----------
|	 |		| SIZE	 |
|        |		----------
|	 |		
----------	


execution details:

1. when need new proc nad not ennough space is sys buffer
    (a) remove  some, marking JMPADR as NIL
    (b) take space on either first fit or some LRU scheme


code format for call  within  lisp lib function

1. macro-generate a CALL LSPLIB
		     <relative pos of FOO>
		     <relative pos of next byte>

2. CALL LSPLIB  will be assembled as CALL -1 and lisp loader
   will fill in the actual address at run-time.

3. entering LSPLIB will:
    (a) pop the return since we won't use it
    (b) get rel byte # for return, and push it
    (c) get name of executing FASL, and push it
    (d) get name of called routine, and map into memory
    (e) push [LSPRET] as return address whwn leaving
    (f) jump to called code (= loc of FASL in system buffer

4. entering LSPRET will:
    (a) pop function name
    (b) map it into memory
    (c) pop rel. byte #
    (d) make JMPADR (= system buffer loc +  rel. byte #)


code format for call of lisp lib from LISP

1. recognized as FASL we:
    (a) check JMPADR
        if ≠NIL, do it
        if NIL, use file information to load FASL, and update JMPADR.

code format for FASL function:

1. on disk:

 (a) sequence of strings, representing names of external references in this FASL
 (b) string representing FASL's name
 (c) code bytes: Z-80 position-independent code
		 CALL LSPLIB's  as CALL -1

2. in memory:
 (a) pointers to values representing FASL value (derived from (a) above)
 (b) pointer to value represneting this FASL (from (b) above)
 (c)  code bytes: z-80 position-independent
		  CALL LSPLIB now filled in.


example:

(de fact (x) (if (eq x 0) 1 (mul x (fact (sub1 x)))))

		    disk:           MEMORY

	|   5       "fix",0         5 POINTER TO FIX
EXTERNAL|   4       "mul",0         4 POINTER TO MUL
 REFS.  |   3       "sub1",0        3 POINTER TO SUB1
	|   2       "eq",0          2 POINTER TO EQ
	|   1       "fact",0        1 POINTER TO FACT

FASL NAME   0       "fact",0        0 POINTER TO FACT

BYTE NO.  CODE

0 	PUSH 	BC
1	 LD 	A,1
2-4 	CALL 	LSPLIB
5	5	; POSITION OF FIX 
6	7	; REL. POS. OF NEXT BYTE
7	POP	DE
8	PUSH	DE	;SAVE  x
9-11	CALL	LSPLIB
12	2		; EQ
13	14		; NEXT BYTE #
14	RET	Z
15	POP	BC	; GET x
16	PUSH	BC
17	CALL	LSPLIB
20	3		;SUB1
21	22
22-24	CALL	LSPLIB	; IN THIS CASE WE COULD DIRECTLY CODE THE CALL, BUT...
25	1		; FACT
26	27
27-28	MOVOBJ	DE,BC
29	POP	BC	; 
30-32	CALL	LSPLIB
33	4		;MUL
34	35
36	RET
 behavior of loader:

 using FILE, RECord, and POSition  information, read in information.
 (a) resolving strings into atom pointers.
 (b) checking through code for CALL -1, resolving these to CALL LSPLIB.
 (c) error check for lossy code?

 questions:
 (a) how to format file for  loader?

	(1) assemble (with macros to generate  tables)
	(2) link  and save as com file.
	(3) run file hack to build a loader file

 (b) should allow multiple functions on same file, and should allow several files
	call (LSPLIB filename)
	file has directory, built by a-3 (above)
	LSPLIB uses this directory to build the FASL values.

all this imples that the assembled file has a table of contents:

	    fasl name string1
	    rel pos
	     ...

	    fasl name stringn
	    rel pos

		fasl1 org
		. . .
		fasln org

and  LSPLIB uses this table of contents to build the initial FASL values